from builtins import ValueError  # 添加ValueError导入
from enum import Enum
from langchain_community.document_loaders import UnstructuredMarkdownLoader


class LoadMode(str, Enum):
    SINGLE = "single"  # single 将 Markdown 文件摄取到单个 Document
    ELEMENTS = "elements"  # elements 模式返回多个 Document，并保留titles、list items 等元素


async def load(path: str, mode: LoadMode = LoadMode.SINGLE) -> list:
    if not isinstance(mode, Enum):
        raise ValueError(f"Invalid mode: {mode}.")

    loader = UnstructuredMarkdownLoader(path, mode=mode.value)
    data = loader.load()
    return data
